<?php
class SpaceManagerController extends CustomControllerAction {
protected $identity = null;
    public function init() {
        parent::init();
        $this->breadcrumbs->addStep('用户账户', $this->getUrl(null, 'account'));
        $this->breadcrumbs->addStep('空间管理', $this->getUrl(null, 'spacemanager'));
        
        $auth = Zend_Auth::getInstance();
        if (!$auth->hasIdentity()) {
            $this->_redirect($this->getUrl('login', 'account'));
        }
        $this->identity = $auth->getIdentity();
    }
    
	public function indexAction() {
		
		$space = new DatabaseObject_Space($this->db);
		if (!$space->load($this->identity->userid)) {
			$this->_redirect($this->getUrl('index', 'account'));
			$this->messager->addMessage('载入空间信息失败');
		} else {
			
		}
		$this->view->space = $space;
	}
	
	public function customizeAction() {
		$request = $this->getRequest();
		
		$fp = new FormProcessor_CustomizeSpace($this->db, $this->identity->userid);
		$menu = $fp->space->getMenuList();
		$item = $fp->space->getItemList();
		
		if ($request->isPost()) {
			if ($fp->process($request)) {
				$this->_redirect($this->getUrl('index'));
				$this->messager->addMessage('空间信息已更新');
			}
		}
		
		$this->breadcrumbs->addStep('信息编辑', $this->getUrl('customize'));
		$this->view->menu = $menu;
		$this->view->item = $item;
		$this->view->fp = $fp;
	}
}
?>